package gxmzu.gxmzuproject.controller;

import gxmzu.gxmzuproject.service.MiniCarItemService;
import gxmzu.gxmzuproject.param.MiniCarItemQueryParam;
import gxmzu.gxmzuproject.vo.MiniCarItemQueryVo;
import gxmzu.gxmzuproject.entity.MiniCarItem;
import gxmzu.gxmzuproject.config.common.BaseController;
import gxmzu.gxmzuproject.config.common.ApiResult;
import gxmzu.gxmzuproject.config.common.Paging;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;


/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Code534
 * @since 2022-08-10
 */
@Slf4j
@RestController
@RequestMapping("/miniCarItem")
@Api(value = "小程序-拼车-模块", tags = {"小程序-拼车-模块"})
public class MiniCarItemController extends BaseController {

    @Autowired
    private MiniCarItemService miniCarItemService;

    /**
    * 添加
    */
    @PostMapping("/add")
    @ApiOperation(value = "添加MiniCarItem对象",notes = "添加")
    public ApiResult<Boolean> addMiniCarItem(@Valid @RequestBody MiniCarItem miniCarItem) {
        boolean flag = miniCarItemService.save(miniCarItem);
        return ApiResult.result(flag);
    }

    /**
    * 修改
    */
    @PutMapping("/update")
    @ApiOperation(value = "修改MiniCarItem对象",notes = "修改")
    public ApiResult<Boolean> updateMiniCarItem(@Valid @RequestBody MiniCarItem miniCarItem) {
        boolean flag = miniCarItemService.updateById(miniCarItem);
        return ApiResult.result(flag);
    }

    /**
    * 删除
    */
    @DeleteMapping("/delete/{id}")
    @ApiOperation(value = "删除MiniCarItem对象",notes = "删除")
    public ApiResult<Boolean> deleteMiniCarItem(@PathVariable String id) {
        boolean flag = miniCarItemService.removeById(id);
        return ApiResult.result(flag);
    }

    /**
    * 获取
    */
    @GetMapping("/info/{id}")
    @ApiOperation(value = "获取MiniCarItem对象详情",notes = "查看")
    public ApiResult<MiniCarItemQueryVo> getMiniCarItem(@PathVariable String id) {
        MiniCarItemQueryVo miniCarItemQueryVo = miniCarItemService.getMiniCarItemById(id);
        return ApiResult.ok(miniCarItemQueryVo);
    }

    /**
     * 分页列表
     */
    @PostMapping("/getPageList")
    @ApiOperation(value = "获取MiniCarItem分页列表",notes = "分页列表")
    public ApiResult<Paging<MiniCarItemQueryVo>> getMiniCarItemPageList(@Valid @RequestBody(required = false) MiniCarItemQueryParam miniCarItemQueryParam) {
        Paging<MiniCarItemQueryVo> paging = miniCarItemService.getMiniCarItemPageList(miniCarItemQueryParam);
        return ApiResult.ok(paging);
    }

}

